<template>
  <div id="myChart"></div>
</template>

<script>
export default {
  data() {
    return {
      // 接受的数据
      drawing: {
        backgroundColor: "#fff",
        title: {
          // Customized Pie 标题
          text: "",
          left: "center",
          top: 20,
          textStyle: {
            color: "#ccc",
          },
        },

        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },

        visualMap: {
          show: false,
          min: 80,
          max: 600,
          inRange: {
            colorLightness: [0.5, 1],
          },
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "55%",
            center: ["50%", "50%"],
            data: [
            ].sort(function (a, b) {
              return a.value - b.value;
            }),
            roseType: "radius",
            label: {
              color: "rgba(255, 255, 255, 0.3)",
            },
            labelLine: {
              lineStyle: {
                color: "rgba(255, 255, 255, 0.3)",
              },
              smooth: 0.2,
              length: 10,
              length2: 20,
            },
            itemStyle: {
              color: "red",
              shadowBlur: 200,
              shadowColor: "rgba(0, 0, 0, 0.5)",
            },

            animationType: "scale",
            animationEasing: "elasticOut",
            animationDelay: function (idx) {
              return Math.random() * 200;
            },
          },
        ],
      },
    };
  },
  methods: {
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      // 绘制图表
      myChart.setOption(this.drawing);
      
    },
    // 更改数据
    updateData(value) {
      // 第一个数据没有打印
      this.dataList = value;
      // console.log(this.dataList)
      // console.log(this.drawing.series[0].data);
      this.drawing.series[0].data = this.dataList.sort(function (a, b) {
        return a.value - b.value;
      });
      // console.log(this.drawing.series[0].data);
      this.drawLine();
    },
  },
  // 创建
  created() {},
  // 挂载
  mounted() {},
  // 更改
  updated() {},
};
</script>
<style scoped>
#myChart {
  height: 450px;
  width: 700px;
}
</style>